package com.deltabot.master.heartbeatserver;

import java.util.ArrayList;
import java.util.List;

public class cache {

    private static List<server> serverList = new ArrayList<server>();

    public static void addServer(String Hostname, String IP, String Port, String Map, String CurrentPlayers, String MaxPlayers, String Game, String GameType, String Premium,String Hardcore, String Country){

        for(server server : serverList){
            if((server.IP == IP) && (server.Port == Port)){
                //The server is already in our cache, we should remove the old one, and insert the new data
                serverList.remove(serverList.indexOf(server));
                break;
            }
        }

        server S = new server();

        S.Hostname = Hostname;
        S.Port = Port;
        S.IP = IP;
        S.Map = Map;
        S.CurrentPlayers = CurrentPlayers;
        S.MaxPlayers = MaxPlayers;
        S.Game = Game;
        S.GameType = GameType;
        S.Premium = Premium;
        S.Hardcore = Hardcore;
        S.Country = Country;

        serverList.add(S);

    }

    public static server[] getCachedServers(){

        return serverList.toArray(new server[serverList.size()]);

    }
}
